/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MSDP_MESSAGE_BUILDER_H
#define MSDP_MESSAGE_BUILDER_H

#include <json/json.h>
#include "communication_common.h"

namespace OHOS {
namespace Msdp {
class MessageBuilder {
public:
    MessageBuilder();
    MessageBuilder(std::shared_ptr<SpatialRequest> request);
    MessageBuilder(std::shared_ptr<SpatialResponse> response);
    MessageBuilder(int sessionId, std::string& str);
    ~MessageBuilder();
    bool IsRequest();
    bool IsResponse();
    std::shared_ptr<SpatialRequest> GetRequest();
    std::shared_ptr<SpatialResponse> GetResponse();
    std::string GetString();

private:
    void BuildMapJson(std::shared_ptr<SpatialMap> map, Json::Value& root);
    void BuildMapJsonCoordinate(Json::Value &jsCoordinate, const DeviceInfo &info,
        const DeviceCoordinate &coordinate);
    std::string BuildStringForRequest(std::shared_ptr<SpatialRequest> request);
    std::string BuildStringForResponse(std::shared_ptr<SpatialResponse> response);
    std::shared_ptr<SpatialMap> BuildMapObject(Json::Value& data);
    void BuildRequest(Json::Value& root, int sessionId, std::shared_ptr<SpatialRequest> request);
    void BuildResponse(Json::Value& root, int sessionId, std::shared_ptr<SpatialResponse> response);
    enum {
        TYPE_NONE  = 0,
        TYPE_REQUEST,
        TYPE_RESPONSE,
    };
    uint32_t type_ {TYPE_NONE};
    std::shared_ptr<SpatialRequest> request_;
    std::shared_ptr<SpatialResponse> response_;
    std::string messageStr_ {""};
};
} // namespace Msdp
} // namespace OHOS

#endif // MSDP_MESSAGE_BUILDER_H